import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * docDimension-单据维度
 * @date: 2019-09-19
 */
import request from 'utils/request';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
import { CPAAS_IAM } from 'utils/config';
var organizationId = getCurrentOrganizationId();
/**
 * 查询单据维度定义
 * @param {Object} params - 查询参数
 */

export function query(_x) {
  return _query.apply(this, arguments);
}
/**
 * 查询单据维度定义详情
 * @param {Object} params - 查询参数
 */

function _query() {
  _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : "", "doc-type/dimensions"), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _query.apply(this, arguments);
}

export function queryDetail(_x2) {
  return _queryDetail.apply(this, arguments);
}
/**
 * 新建单据维度
 * @param {Object} params - 查询参数
 */

function _queryDetail() {
  _queryDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var dimensionId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            dimensionId = params.dimensionId;
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : "", "doc-type/dimensions/").concat(dimensionId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryDetail.apply(this, arguments);
}

export function create(_x3) {
  return _create.apply(this, arguments);
}
/**
 * 修改单据维度
 * @param {Object} params - 查询参数
 */

function _create() {
  _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : "", "doc-type/dimensions"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _create.apply(this, arguments);
}

export function update(_x4) {
  return _update.apply(this, arguments);
}

function _update() {
  _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : "", "doc-type/dimensions"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _update.apply(this, arguments);
}